package edu.pku.sei.transformation.editor.views.tree;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;

import edu.pku.sei.modeler.images.ImageProvider;
import edu.pku.sei.modeler.model.core.MetaAttribute;
import edu.pku.sei.modeler.model.core.MetaClass;
import edu.pku.sei.modeler.model.core.MetaClassifier;
import edu.pku.sei.modeler.model.core.MetaDataType;
import edu.pku.sei.modeler.model.core.MetaGeneralization;
import edu.pku.sei.modeler.model.core.MetaModel;
import edu.pku.sei.modeler.model.core.MetaNamedElement;
import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.modeler.model.core.MetaReference;

public class ModelTreeViewerLabelProvider implements ILabelProvider {

	public Image getImage(Object element) {
		ImageDescriptor iDesc;
		if (element instanceof MetaDataType) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.ATTRIBUTE);
		} else if (element instanceof MetaModel) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.MODEL_VIEW);
		} else if (element instanceof MetaPackage) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.PACKAGE);
		} else if (element instanceof MetaClassifier) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.CLASS_ENTRY);
		} else if (element instanceof MetaAttribute) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.ATTRIBUTE);
		} else if (element instanceof MetaReference) {
			iDesc = ImageProvider
					.getImageDescriptor(ImageProvider.ASSOCIATION_ENTRY);
		} else if (element instanceof MetaGeneralization) {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.CLASS_ENTRY);
		} else {
			iDesc = ImageProvider.getImageDescriptor(ImageProvider.UNKNOWN);
		}
		return iDesc.createImage();
	}

	public String getText(Object element) {
		if (element instanceof MetaAttribute) {
			MetaAttribute attri = (MetaAttribute) element;
			String text = attri.getName();
			if (attri.getType() != null) {
				text += ":" + attri.getType().getName();
			}
			return text;
		} else if (element instanceof MetaReference) {
			MetaReference ref = (MetaReference) element;
			String text = ref.getName();
			if (ref.getType() != null) {
				text += ":" + ref.getType().getName();
			}
			if (ref.getOpposite() != null) {
				text += "-" + ref.getOpposite().getFullName();
			}
			return text;
		} else if (element instanceof MetaGeneralization) {
			MetaGeneralization gen = (MetaGeneralization) element;
			String text = "SuperClass:" + gen.getGeneral().getFullName();
			return text;
		} else if (element instanceof MetaClass) {
			MetaClass cls = (MetaClass) element;
			String text = cls.getName();
			return text;
		} else if (element instanceof MetaNamedElement) {
			return ((MetaNamedElement) element).getName();
		} else {
			return "default";
		}
	}

	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub

	}

	public void dispose() {
		// TODO Auto-generated method stub

	}

	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub

	}

}
